"use strict";
/**
 * @ Author: Yoann Meclot. MSay2
 * @ Created on: 2020-08-28 09:48:25
 * @ Modified on: 2021-06-14 18:12:03
 *
 * @version 1.5
 */
/**
 * Copyright (c) 2020-2021 MSay2 (Yoann Meclot) - @msay2/tspoet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Kind = exports.TSPoet = void 0;
const fs = __importStar(require("fs"));
const Exceptions_js_1 = require("../util/Exceptions.js");
const Objects_js_1 = require("../util/Objects.js");
const CodeWriter_js_1 = require("./CodeWriter.js");
/**
 * TSPoet is a mean to create TypeScript source files with elements Classes, Enumerations and Interfaces.
 *
 * @class `TSPoet`
 * @version 1.3
 */
class TSPoet {
    /**
     * create new TS file and write element type.
     *
     * @param path The location path to generate the file.
     * @param tsType The object type to be building.
     * @throws {TSPoetException} Check if the path is undefined or null.
     * @throws {TSPoetException} Check if the TSType object is undefined or null.
     * @type {void}
     * @since 1.0
     */
    static writeFile(path, tsType) {
        if (Objects_js_1.Objects.isNull(path))
            throw new Exceptions_js_1.TSPoetException("TSPoet must have a non-null path.");
        if (Objects_js_1.Objects.isNull(tsType))
            throw new Exceptions_js_1.TSPoetException("TSPoet must have a non-null TSType object.");
        let code = "";
        switch (tsType.mKind) {
            case Kind.CLASS:
                code = tsType.emitClass(new CodeWriter_js_1.CodeWriter()).toString();
                break;
            case Kind.ENUM:
                code = tsType.emitEnum(new CodeWriter_js_1.CodeWriter()).toString();
                break;
            case Kind.INTERFACE:
                code = tsType.emitInterface(new CodeWriter_js_1.CodeWriter()).toString();
                break;
        }
        let name = tsType.mName;
        let url = `${path}/${name}.ts`;
        fs.writeFileSync(url, "", { encoding: "utf-8" });
        this.emit(url, code);
    }
    static emit(url, block) {
        fs.appendFileSync(url, `${block}`, { encoding: "utf-8" });
    }
}
exports.TSPoet = TSPoet;
/**
 * Internal enum for TSPoet.
 *
 * @ignore
 */
var Kind;
(function (Kind) {
    Kind["CLASS"] = "class";
    Kind["ENUM"] = "enum";
    Kind["INTERFACE"] = "interface";
    Kind["UNDEFINED"] = "";
})(Kind = exports.Kind || (exports.Kind = {}));
//# sourceMappingURL=TSPoet.js.map